<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <img id="img" />
    <script>
      /*
      将图片二进制数据转BLOB对象
      1. 将二进制转换成临时地址 URL.createObjectURL()
      2. 选择img标签设置转换后的地址
      针对小文件，使用base64编码，将二进制数据转换成普通可见字符
      */
      const xhr = new XMLHttpRequest();
      xhr.open("GET", "http://localhost:3008/img");
      xhr.responseType = "blob";
      xhr.onload = function () {
        console.log(xhr.response);
        const src = URL.createObjectURL(xhr.response);
        img.src = src;
      };

      xhr.send();
    </script>
  </body>
</html>
